<template>
	<view class="home_wrap">
		<view class="head_wrap" :style="'height:' + 250 - statusBarHeight + 'px;'">
			<view :style="'height:' + statusBarHeight + 'px'"></view>
			<view class="title" :style="'height:' + navigatorBarHeight + 'px'">首页</view>
			<view class="search_item" @click="focusinput()">
				<image :src="remoteUrl + 'search_icon.png'" class="search_icon" mode=""></image>
				<input type="text" placeholder="搜索" disabled="true" @focus="focusinput" />
			</view>
			<swiper :autoplay="true" class="swiper_wrap" circular="true">
				<swiper-item v-for="(item,index) in banner_list">
					<image :src="ossUrl + item.image" class="banner_img" mode=""></image>
				</swiper-item>
			</swiper>
		</view>

		<view class="flex-row equal-division">
			<view class="flex-col items-center group_4 group_16"
				@click="jumpLink('/pages/connections/connections',false)">
				<image class="image_7" :src="remoteUrl + 'connections_img.png'" />
				<text class="font_2 mt-6">人脉</text>
			</view>
			<view class="flex-col items-center group_4 equal-division-item_2"
				@click="jumpLink('/pages/hall/hall',false)">
				<image class="image_7" :src="remoteUrl + 'hall_img.png'" />
				<text class="font_2 mt-6">供需大厅</text>
			</view>
			<view class="flex-col items-center group_4 group_15"
				@click="jumpLink('/pages/pages-list/forum_page/forum_page',true)">
				<image class="image_7" :src="remoteUrl + 'forum_img.png'" />
				<text class="font_2 mt-6">官方发布</text>
			</view>
			<view v-if="config == 1" class="flex-col items-center group_4 equal-division-item_2"
				@click="jumpLink('/pages/coures/coures',false)">
				<image class="image_7" :src="remoteUrl + 'course_img.png'" />
				<text class="font_2 mt-6">大咖课程</text>
			</view>
		</view>
		<!-- 通告栏 -->
		<view style="width: 90%;margin: 0 auto;" @click="toForum()">
			<uni-notice-bar show-icon scrollable :text="notice" />
		</view>

		<!-- 供需列表 -->
		<view class="flex-col group_5">
			<view class="flex-row justify-between items-center">
				<text class="font_3">最新需求</text>
				<view class="flex items-center group_6" @click="jumpLink('/pages/hall/hall',false)">
					<text class="font_4">更多</text>
					<image class="image_8 ml-6" :src="remoteUrl + 'right_icon.png'" />
				</view>
			</view>
			<view class="flex-col mt-10">
				<view class="flex-col list-item mt-10" v-for="(item,index) in need_list" :key="index"
					@click="toDetail(item.id)">
					<view class="flex-row justify-between items-center">
						<text class="font_5 row_1" style="width: 80%;">{{ item.title }}</text>
						<view class="flex">
							<!-- <view class="flex-col justify-start items-center text-wrapper view"
								v-if="item.type_id == 1">
								<text class="font_6">供</text>
							</view>
							<view class="flex-col justify-start items-center text-wrapper need"
								v-if="item.type_id == 2">
								<text class="font_6">需</text>
							</view> -->
							<view class="flex-col justify-start items-center text-wrapper not" v-if="item.status == 0">
								<text class="font_6">未解决</text>
							</view>
							<view class="flex-col justify-start items-center text-wrapper already"
								v-if="item.status == 1">
								<text class="font_6">已解决</text>
							</view>
						</view>
					</view>
					<view class="font_7 mt-14 row_1">
						<rich-text :nodes="item.content"></rich-text>
					</view>

					<!-- <text class="font_7 mt-14 row_1">{{ item.content }}</text> -->
					<view class="flex-row justify-between items-center mt-14">
						<view class="flex-row items-center">
							<image class="image_9" :src="ossUrl + item.user_avatar" />
							<text class="font_8 text_10">{{ item.user_name }}</text>
							<view class="section_10"></view>
							<text class="font_8 text_31">{{ item.user_company_name }}</text>
						</view>
						<text class="font_9 text_12">{{ item.updatetime }}</text>
					</view>
				</view>
			</view>
		</view>
		<!-- 活动、公告 -->
		<view class="group_5">
			<view class="flex-row justify-between items-center" style="margin-top: 20rpx;">
				<text class="font_3">推荐</text>
				<view class="flex items-center group_6"
					@click="jumpLink('/pages/pages-list/forum_page/forum_page',true)">
					<text class="font_4">更多</text>
					<image class="image_8 ml-6" :src="remoteUrl + 'right_icon.png'" />
				</view>
			</view>
		</view>
		<view class="list_wrap" v-for="(item,index) in activity_list">
			<view class="flex-col list-item" @click="toActivity(item.id)" v-if="index == 0">
				<view class="flex-row">
					<image class="shrink-0 image_8" :src="ossUrl + item.image" />
					<view class="flex-col flex-1 group_5">
						<text class="font_2 row_2">{{ item.title }}</text>
						<text class="mt-16 font_3 text_2 row_1">活动地址：{{ item.address }}</text>
					</view>
				</view>
				<view class="flex-row justify-between items-center mt-8">
					<text class="font_4 text_2">开始时间：{{ item.start_time }}</text>
					<view
						:class="[(new Date().getTime() < new Date(item.start_time).getTime()) ? 'button' : (new Date().getTime() > new Date(item.start_time).getTime() && (new Date().getTime() < new Date(item.end_time).getTime())) ? 'button_1' : 'button_2','flex']">
						<text
							class="font_5">{{ new Date().getTime() < new Date(item.start_time).getTime() ? '报名中' : (new Date().getTime() > new Date(item.start_time).getTime() && (new Date().getTime() < new Date(item.end_time).getTime())) ? '已开始' : '已结束' }}</text>
					</view>
				</view>
			</view>
		</view>
		<view class="list_wrap" v-for="(item,index) in notice_list">
			<view class="flex-col section_7" @click="toNotice(item.id)" v-if="item.image && index <= 1">
				<view class="flex-col items-start relative group_5">
					<text class="font row_1" style="width: 82%;">{{ item.title }}</text>
					<!-- <view class="font_2 text_7 row_1">{{ item.content }}</view> -->
					<!-- <rich-text class="font_2 text_7 row_1" style="width: 80%;" :nodes="item.content"></rich-text> -->
					<image class="image_8 pos_9" :src="ossUrl + item.image" />
				</view>
				<text class="self-start font_3 text_3 mt-14">{{ item.createtime }}</text>
				<!-- <view class="top_up" v-if="item.is_top_switch == 1">置顶</view> -->
			</view>
			<view class="flex-col section_7" @click="toNotice(item.id)" v-if="!item.image && index <= 1">
				<view class="flex-col items-start relative group_5">
					<text class="font">{{ item.title }}</text>
					<!-- <view class="font_2 text_7 row_1" style="width: 100%;">{{ item.content }}</view> -->
					<!-- <rich-text class="font_2 text_7 row_1" style="width: 100%;" :nodes="item.content"></rich-text> -->
				</view>
				<text class="self-start font_3 text_3 mt-14">{{ item.createtime }}</text>
				<!-- <view class="top_up" v-if="item.is_top_switch == 1">置顶</view> -->
			</view>
		</view>

		<!-- 推荐课程 -->
		<view class="flex-col course_wrap mt-10" v-if="config == 1">
			<view class="flex-row justify-between items-center">
				<text class="font_3">推荐课程</text>
				<view class="flex items-center course_title" @click="jumpLink('/pages/coures/coures',false)">
					<text class="font_4">更多</text>
					<image class="image_8 ml-6" :src="remoteUrl + 'right_icon.png'" />
				</view>
			</view>
			<view class="grid">
				<view class="grid-item" v-for="(item,index) in course_list"
					@click="jumpLink('/pages/pages-list/coures_detail/coures_detail?id='+item.id,true)">
					<image class="image_10" :src="ossUrl + item.image" mode="aspectFill" />
					<view class="cont_item">
						<text class="font text_4 mt-10 row_2">{{ item.title }}</text>
						<view class="font_9 mt-6 flex justify-between">
							<text class="font_8">观看人数：{{ item.watch_number }}</text>
							{{ item.createtime }}
						</view>
						<view class="flex justify-between items-center mt-12">
							<view class="price">{{ item.price }}元</view>
							<view class="flex">
								<image @click.prevent="bindCollect(item.id,item.user_star,index)" class="collect_icon"
									v-if="item.user_star == 0" :src="remoteUrl + 'collect_n.png'" mode=""></image>
								<image @click.prevent="bindCollect(item.id,item.user_star,index)" class="collect_icon"
									v-if="item.user_star == 1" :src="remoteUrl + 'collect_y.png'" mode=""></image>
								<view class="flex-col justify-start items-center button" @click.prevent="toPay(item)">
									<text class="font_12">{{ item.user_buy == 0 ? '立即购买' : '已购买'}}</text>
								</view>
							</view>
						</view>
					</view>
				</view>
			</view>
		</view>

		<CustomTabBar :selected="0"></CustomTabBar>
	</view>
</template>

<script>
	import {
		remoteUrl,
		ossUrl
	} from '@/utils/config.js'
	import {
		login
	} from '@/api/login.js'
	import {
		getBanner,
		new_Task,
		course_index
	} from '@/api/home.js'
	import {
		starCourse
	} from '@/api/coures.js'
	import {
		getNotice,
		getActivity
	} from '@/api/forum.js'
	import {
		baseInfo
	} from '@/api/mine.js'
	import CustomTabBar from "@/components/CustomTabBar/CustomTabBar.vue"
	const app = getApp()
	export default {
		components: {
			CustomTabBar
		},
		data() {
			return {
				remoteUrl: remoteUrl,
				ossUrl: ossUrl,
				statusBarHeight: app.globalData.navigator.statusBarHeight,
				navigatorBarHeight: app.globalData.navigator.navigatorBarHeight,
				search_text: '', // 搜索
				banner_list: [], // 轮播图
				need_list: [],
				course_list: [],
				notice_list: [],
				activity_list: [],
				notice: '',
				notice_id: '',
				config: 0
			};
		},
		onLoad() {
			this.getBannerFun()
			this.getActivityFun()
		},
		onShow() {
			this.getNoticeFun()
			this.baseInfoFun()
			this.getTask()
			this.getCourse()
		},
		onShareAppMessage(res) { //发送给朋友
			return {
				title: '小程序分享',
				imageUrl: '',
			}
		},
		methods: {
			baseInfoFun() {
				baseInfo().then(res => {
					let item = res.data.find(item => item.id == 27)
					wx.setStorageSync('config', item.value)
					this.config = item.value
				})
			},
			// 获取banner
			getBannerFun() {
				getBanner().then(res => {
					if (res.code == 1) {
						this.banner_list = res.data
					}
				})
			},
			getNoticeFun() {
				getNotice().then(res => {
					if (res.code == 1) {
						this.notice_list = res.data
						this.notice = res.data[0].title
						this.notice_id = res.data[0].id
					}
				})
			},
			// 获取活动列表
			getActivityFun() {
				getActivity().then(res => {
					if (res.code == 1) {
						this.activity_list = res.data
					}
				})
			},
			// 获取最新供需
			getTask() {
				new_Task().then(res => {
					if (res.code == 1) {
						this.need_list = res.data
					}
				})
			},
			// 获取推荐课程
			getCourse() {
				course_index().then(res => {
					if (res.code == 1) {
						this.course_list = res.data
					}
				})
			},
			toForum() {
				uni.navigateTo({
					url: '/pages/pages-list/forum_detail/forum_detail?id=' + this.notice_id
				})
			},
			// 跳转购买
			toPay(item) {
				if (!uni.getStorageSync('userInfo')) {
					uni.reLaunch({
						url: '/pages/login/login'
					})
				}
				if (item.user_buy == 1) return
				uni.navigateTo({
					url: '/pages/pages-list/couresOrder/couresOrder?detail=' + encodeURIComponent(JSON.stringify(
						item))
				})
			},
			jumpLink(link, type) {
				if (type) {
					if (!uni.getStorageSync('userInfo')) {
						uni.reLaunch({
							url: '/pages/login/login'
						})
					}
					uni.navigateTo({
						url: link,
					});
				} else {
					uni.switchTab({
						url: link
					})
				}
			},
			// 收藏
			bindCollect(id, flag, index) {
				starCourse({
					id
				}).then(res => {
					if (res.code == 1) {
						uni.showToast({
							title: flag == 0 ? '收藏成功' : '取消收藏成功',
							icon: 'none'
						})
						this.course_list[index].user_star = (flag == 0 ? 1 : 0)
					}
				})
			},
			focusinput(e) {
				uni.navigateTo({
					url: '/pages/search_page/search_page'
				})
			},
			toActivity(id) {
				uni.navigateTo({
					url: '/pages/pages-list/activity_detail/activity_detail?id=' + id
				})
			},
			toNotice(id) {
				uni.navigateTo({
					url: '/pages/pages-list/forum_detail/forum_detail?id=' + id
				})
			},
			toDetail(id) {
				if (!uni.getStorageSync('userInfo')) {
					uni.reLaunch({
						url: '/pages/login/login'
					})
				}
				uni.navigateTo({
					url: '/pages/pages-list/demand_detail/demand_detail?id=' + id
				})
			},
		},
	};
</script>

<style lang="scss" scoped>
	.home_wrap {
		padding-bottom: 120rpx;

		.head_wrap {
			width: 100vw;
			// height: 550rpx;
			background: linear-gradient(180deg, #1C41F1 0%, #1c41f100 100%);
			padding: 0 30rpx;

			.title {
				display: flex;
				align-items: center;
				color: #fff;
				font-size: 36rpx;
			}

			.search_item {
				width: 690rpx;
				height: 76rpx;
				margin-top: 20rpx;
				display: flex;
				align-items: center;
				background: #fff;
				padding: 0 24rpx;
				border-radius: 58rpx;

				.search_icon {
					width: 28rpx;
					height: 28rpx;
					margin-right: 6rpx;
				}
			}
		}

		// 轮播图
		.swiper_wrap {
			width: 690rpx;
			height: 248rpx;
			margin: 20rpx auto;

			.banner_img {
				width: 100%;
				height: 100%;
				border-radius: 20rpx;
			}
		}

		.equal-division {
			// margin-top: 10rpx;
			padding: 0 14rpx;

			.group_4 {
				flex: 1 1 180rpx;

				.image_7 {
					width: 112rpx;
					height: 112rpx;
				}

				.font_2 {
					font-size: 28rpx;
					font-weight: bold;
					color: #000000;
				}
			}

			.group_16 {
				padding: 8rpx 0 10.06rpx;
			}

			.equal-division-item_2 {
				padding: 8rpx 0 10rpx;
			}

			.group_15 {
				padding: 8rpx 0 10.4rpx;
			}
		}

		// 供需列表
		.group_5 {
			padding: 0 28rpx;

			.font_3 {
				font-size: 36rpx;
				font-weight: bold;
				color: #000000;
			}

			.group_6 {
				margin-right: 6rpx;

				.font_4 {
					font-size: 28rpx;
					color: #7b7b7b;
				}

				.image_8 {
					width: 12rpx;
					height: 24rpx;
				}
			}

			.list-item {
				padding: 22rpx 11.86rpx 16rpx 17.72rpx;
				background-color: #ffffff;
				border-radius: 12rpx;
				border: solid 2rpx #1c41f1;

				&:first-child {
					margin-top: 0;
				}

				.font_5 {
					font-size: 32rpx;
					color: #000000;
				}

				.text-wrapper {
					margin-right: 10rpx;

					.font_6 {
						font-size: 26rpx;
						color: #ffffff;
					}
				}

				.view {
					padding: 3rpx 7rpx;
					background-color: #70d042;
					border-radius: 4rpx;
				}

				.need {
					padding: 3rpx 7rpx;
					background-color: #f8d53a;
					border-radius: 4rpx;
				}

				.not {
					padding: 3rpx 7rpx;
					background-color: #999999;
					border-radius: 4rpx;
				}

				.already {
					padding: 3rpx 7rpx;
					border-radius: 4rpx;
					background: #1C41F1;
				}

				.font_7 {
					font-size: 26rpx;
					color: #000000;
				}

				.image_9 {
					border-radius: 20rpx;
					width: 40rpx;
					height: 40rpx;
				}

				.font_8 {
					font-size: 24rpx;
					color: #000000;
				}

				.text_10 {
					margin-left: 9.08rpx;
				}

				.section_10 {
					margin-left: 15.92rpx;
					background-color: #d9d9d9;
					width: 2rpx;
					height: 24rpx;
				}

				.text_31 {
					margin-left: 14.84rpx;
				}

				.font_9 {
					font-size: 22rpx;
					color: #000000;
				}

				.text_12 {
					margin-right: 4rpx;
				}
			}
		}

		// 推荐课程
		.course_wrap {
			padding: 0 28rpx;

			.font_3 {
				font-size: 36rpx;
				color: #000000;
				font-weight: bold;
			}

			.course_title {
				margin-right: 6rpx;

				.font_4 {
					font-size: 28rpx;
					color: #7b7b7b;
				}

				.image_8 {
					width: 12rpx;
					height: 24rpx;
				}
			}

			.grid {
				.grid-item {
					width: 690rpx;
					margin: 0 auto 20rpx;
					display: flex;
					align-items: center;
					justify-content: space-between;
					padding: 20.72rpx 11rpx 19rpx 13rpx;

					.image_10 {
						border-radius: 10rpx;
						width: 200rpx;
						height: 150rpx;
					}

					.cont_item {
						width: 68%;

						.font {
							font-size: 30rpx;
							color: #000000;
						}

						.font_9 {
							font-size: 24rpx;
							color: #000000;
						}

						.font_8 {
							font-size: 24rpx;
							color: #000000;
						}

						.price {
							color: #1c41f1;
							font-size: 30rpx;
						}

						.collect_icon {
							width: 40rpx;
							height: 40rpx;
							margin-right: 20rpx;
						}

						.button {
							padding: 3rpx 20rpx;
							background-color: #ffffff;
							border-radius: 54rpx;
							border: solid 1rpx #1c41f1;

							.font_12 {
								font-size: 24rpx;
								color: #1c41f1;
							}
						}
					}

				}
			}
		}


		.list_wrap {
			margin-bottom: 20rpx;

			.section_7 {
				width: 690rpx;
				margin: 0 auto;
				padding: 22rpx 22rpx 34rpx;
				background-color: #ffffff;
				border-radius: 10rpx;
				position: relative;

				.top_up {
					padding: 6rpx 8rpx;
					color: #fff;
					font-size: 26rpx;
					background: #70D042;
					position: absolute;
					top: 15rpx;
					right: 15rpx;
					border-radius: 4rpx;
				}

				.group_5 {
					padding: 8rpx 0 18rpx;

					.font {
						font-size: 32rpx;
						color: #000000;
						font-weight: bold;
					}

					.font_2 {
						font-size: 26rpx;
						color: #000000;
					}

					.text_7 {
						width: 80%;
						opacity: 0.8;
						margin-top: 24rpx;
					}

					.image_8 {
						border-radius: 10rpx;
						width: 100rpx;
						height: 100rpx;
					}

					.pos_9 {
						position: absolute;
						right: 0;
						bottom: -20rpx;
					}
				}

				.font_3 {
					font-size: 22rpx;
					color: #000000;
				}

				.text_3 {
					opacity: 0.5;
				}
			}

			.list-item {
				width: 690rpx;
				margin: 0 auto;
				padding: 24rpx 5rpx 16rpx;
				background-color: #ffffff;
				border-radius: 10rpx;

				.image_8 {
					border-radius: 10rpx;
					width: 240rpx;
					height: 180rpx;
				}

				.group_5 {
					margin-right: 4rpx;

					.font_2 {
						font-size: 30rpx;
						color: #000000;
						font-weight: bold;
					}

					.font_3 {
						font-size: 24rpx;
						color: #000000;
					}
				}

				.font_4 {
					font-size: 24rpx;
					color: #000000;
				}

				.text_2 {
					opacity: 0.5;
				}

				.button {
					padding: 5rpx 10rpx;
					background-color: #1c41f1;
					border-radius: 8rpx;

					.font_5 {
						font-size: 26rpx;
						color: #ffffff;
					}
				}

				.button_1 {
					padding: 5rpx 10rpx;
					background-color: #70D042;
					border-radius: 8rpx;

					.font_5 {
						font-size: 26rpx;
						color: #ffffff;
					}
				}

				.button_2 {
					padding: 5rpx 10rpx;
					background-color: #808080;
					border-radius: 8rpx;

					.font_5 {
						font-size: 26rpx;
						color: #ffffff;
					}
				}
			}
		}
	}
</style>